//
//  GRUserConfigure.m
//  YC_GRice
//
//  Created by LiuFeng on 2018/7/26.
//  Copyright © 2018年 YeCai. All rights reserved.
//

#import "GRUserConfigure.h"

@interface GRUserConfigure ()

{
    BOOL itemsInit; // item number
    NSInteger processItems; NSInteger commonItems;
}

@end

@implementation GRUserConfigure

static NSInteger itmeLine_Process = 5;
static NSInteger itmeLine_Common  = 4;

- (NSInteger)numberOfItemInSection:(NSInteger)section {
    if (!itemsInit) {
        commonItems  = (self.commonlyUseArray.count / itmeLine_Common + (self.commonlyUseArray.count % itmeLine_Common > 0 ? 1 : 0)) * itmeLine_Common;
        processItems = (self.orderProcessArray.count / itmeLine_Process + (self.orderProcessArray.count % itmeLine_Process > 0 ? 1 : 0)) * itmeLine_Process;
        itemsInit    = YES;
    }
    return section == 0 ? processItems : commonItems;
}


- (CGSize)sizeItemOfSection:(NSInteger)section {
    if (section == 0) {
        return CGSizeMake(KscreenWidth/itmeLine_Process, KscreenWidth/itmeLine_Process);
    }else {
        return CGSizeMake(KscreenWidth/itmeLine_Common, KscreenWidth/itmeLine_Process);
    }
}

- (GROptionModel *)optionCellAtIndexpath:(NSIndexPath *)indexpath {
    if (indexpath.section == 0) {
        if (indexpath.item < self.orderProcessArray.count) {
            GROptionModel *optionModel = self.orderProcessArray[indexpath.item];
            switch (indexpath.item) {
                case 0:
//                    optionModel.badge  = self.personModel.waitPay;
                    optionModel.badge  = self.personModel.pay;
                    break;
                    
                case 1:
//                    optionModel.badge  = self.personModel.waitSend;
                    optionModel.badge  = self.personModel.use;
                    break;
                    
                case 2:
//                    optionModel.badge  = self.personModel.waitHand;
                    optionModel.badge  = self.personModel.complete;
                    break;
                    
                case 3:
                    optionModel.badge  = self.personModel.comment;
//                    optionModel.badge  = self.personModel.waitPay;
                    break;
                    
                case 4:
//                    optionModel.badge  = self.personModel.returnOrder;
                    optionModel.badge  = self.personModel.refundAndExpired;
                    break;

                default:
                    break;
            }
            
            return optionModel;
        }
    }else {
        if (indexpath.item < self.commonlyUseArray.count) {
            return self.commonlyUseArray[indexpath.item];
        }
    }
    return nil;
}


#pragma Mark  ==== 懒加载
- (NSMutableArray *)orderProcessArray {
    if (!_orderProcessArray) {
        NSArray *process = @[@{@"imgName":@"usercenter_1", @"optionName":@"待付款"},
                             @{@"imgName":@"usercenter_36", @"optionName":@"可使用"},
                             @{@"imgName":@"usercenter_37", @"optionName":@"已消费"},
                             @{@"imgName":@"usercenter_4", @"optionName":@"待评价"},
                             @{@"imgName":@"usercenter_5", @"optionName":@"退款/过期"}];
/*
        NSArray *process = @[@{@"imgName":@"usercenter_1", @"optionName":@"待付款"},
                             @{@"imgName":@"usercenter_2", @"optionName":@"待发货"},
                             @{@"imgName":@"usercenter_3", @"optionName":@"待收货"},
                             @{@"imgName":@"usercenter_4", @"optionName":@"待评价"},
                             @{@"imgName":@"usercenter_5", @"optionName":@"退货/售后"}];
 */
        _orderProcessArray = [NSMutableArray array];
        for (NSDictionary *dic in process) {
            GROptionModel *model = [GROptionModel yy_modelWithDictionary:dic];
            [_orderProcessArray addObject:model];
        }
    }
    return _orderProcessArray;
}

-(NSMutableArray *)commonlyUseArray {
    if (!_commonlyUseArray) {
        NSArray *commonlys = @[@{@"imgName":@"usercenter_38", @"optionName":@"我的买单"},
                               @{@"imgName":@"usercenter_39", @"optionName":@"去过的店"},
                               @{@"imgName":@"usercenter_7", @"optionName":@"我的收藏"},
                                @{@"imgName":@"usercenter_9", @"optionName":@"优惠券"},
                               @{@"imgName":@"usercenter_11", @"optionName":@"联系我们"}];
        /*
        NSArray *commonlys = @[@{@"imgName":@"usercenter_6", @"optionName":@"我的地址"},
                               @{@"imgName":@"usercenter_7", @"optionName":@"我的收藏"},
                               @{@"imgName":@"usercenter_8", @"optionName":@"我的评价"},
                               @{@"imgName":@"usercenter_9", @"optionName":@"优惠券"},
                               @{@"imgName":@"usercenter_10", @"optionName":@"安全认证"},
                               @{@"imgName":@"usercenter_11", @"optionName":@"联系我们"}];
         */
        _commonlyUseArray = [NSMutableArray array];
        for (NSDictionary *dic in commonlys) {
            GROptionModel *model = [GROptionModel yy_modelWithDictionary:dic];
            [_commonlyUseArray addObject:model];
        }
    }
    return _commonlyUseArray;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
